<?php
class Horario_Model extends CI_Model {

    public function get($id = FALSE) {
      if ($id === FALSE) {
        $this->db->select('id,nombre,entrada,salida');
        $this->db->from('horario');
        $query = $this->db->get();
      }else{
           $query = $this->db->get_where('horario', array('id' => $id));
      }
        if ($query->num_rows() > 0) {
            return $query; // just return $query
        }else{
            return null;
        }
    }
    
    public function insert_horario() {
        $this->load->helper('url');

        $data = array(
            'id' => 0,
            'nombre' => $this->input->post('nombre'),
            'entrada' => $this->input->post('entrada'),
            'salida' => $this->input->post('salida'),
        );

        return $this->db->insert('horario', $data);
    }
    
    public function horario_exists($id) {
        $this->db->from('horario');
        $this->db->where('id', $id);        
        $query = $this->db->get();

        if ($query->num_rows() > 0) {
            return TRUE;
        } else {
            return FALSE;
        }
    }
    
    public function delete_horario($id) {
        $this->db->from('horario');
        $this->db->where('id', $id);
        $this->db->delete('horario');
    }
}

?>
